#include "sqlite_manager.h"
#include <iostream>

int main() {
    // 获取SQLite管理器实例
    SQLiteManager& db = SQLiteManager::getInstance();
    
    // 连接数据库
    if (!db.connect("test_hamlog.db")) {
        std::cerr << "无法连接到数据库" << std::endl;
        return 1;
    }
    
    std::cout << "成功连接到数据库" << std::endl;
    
    // 创建测试QSO记录
    QSORecord record;
    record.date = "2023-10-01";
    record.time = "14:30:22";
    record.callsign = "BA1ABC";
    record.band = "20m";
    record.mode = "SSB";
    record.rst_sent = "59";
    record.rst_rcvd = "59";
    record.name = "张三";
    record.qth = "北京";
    record.memo = "测试通联";
    
    // 插入QSO记录
    if (db.insertQSO(record)) {
        std::cout << "成功插入QSO记录" << std::endl;
    } else {
        std::cerr << "插入QSO记录失败" << std::endl;
    }
    
    // 获取所有QSO记录
    std::vector<QSORecord> records = db.getAllQSOs();
    std::cout << "数据库中有 " << records.size() << " 条QSO记录" << std::endl;
    
    for (const auto& rec : records) {
        std::cout << "ID: " << rec.id << ", 呼号: " << rec.callsign 
                  << ", 频段: " << rec.band << ", 模式: " << rec.mode << std::endl;
    }
    
    // 测试JSON操作
    std::string test_json = R"({"config": {"callsign": "BA1ABC", "name": "测试电台"}})";
    if (db.saveJSON("test_config", test_json)) {
        std::cout << "成功保存JSON数据" << std::endl;
    }
    
    std::string loaded_json = db.loadJSON("test_config");
    if (!loaded_json.empty()) {
        std::cout << "加载的JSON数据: " << loaded_json << std::endl;
    }
    
    std::cout << "测试完成" << std::endl;
    
    return 0;
}